﻿var WFM = (function (wfm) {
    data = {
        Keyvalue: '',
        Tablename: '',
        WorkflowId: '',
        WorktaskId: '',
        WorkflowInsId: '',
        WorktaskInsId: '',
        OperatorInsId: ''
    };
    var _TransmitName = ''; //转发姓名字符串

    wfm.init = function (tableName, workFlowId, workTaskId) {
        data.Tablename = tableName;
        data.WorkflowId = workFlowId;
        data.WorktaskId = workTaskId;

        WF.init(tableName, workFlowId, workTaskId);

    };
    wfm.init = function (username, tableName, workFlowId, workTaskId, workFlowInsId, worktaskInsId, operatorInsId) {
        data.Tablename = tableName;
        data.WorkflowId = workFlowId;
        data.WorktaskId = workTaskId;
        data.WorkflowInsId = workFlowInsId;
        data.WorktaskInsId = worktaskInsId;
        data.OperatorInsId = operatorInsId;

        WF.init(tableName, workFlowId, workTaskId, workFlowInsId, worktaskInsId, operatorInsId);
        APP.init(username, workFlowId, workTaskId, workFlowInsId, worktaskInsId, operatorInsId);
    };

    wfm.setData = function (keyValue, tableName, workFlowId, workTaskId, workFlowInsId, worktaskInsId) {
        data.Keyvalue = keyValue;
        data.Tablename = tableName;
        data.WorkflowId = workFlowId;
        data.WorktaskId = workTaskId;

        data.WorkflowInsId = workFlowInsId;
        data.WorktaskInsId = worktaskInsId;
    };
    wfm.setWorkflowInsId = function (workFlowInsId) {
        data.WorkflowInsId = workFlowInsId;
    };
    wfm.setWorktaskInsId = function (worktaskInsId) {
        data.WorktaskInsId = worktaskInsId;
    };
    wfm.setKeyvalue = function (keyValue) {
        data.Keyvalue = keyValue;
    };
    wfm.setOperatorInsId = function (operatorInsId) {
        data.OperatorInsId = operatorInsId;
    };
    wfm.getOperatorInsId = function () {
        var strOperatorInsId = '';
        if (data) {
            strOperatorInsId = data.OperatorInsId;
        }
        return strOperatorInsId;
    };

    //测试用。
    wfm.getWF = function () {
        return _WF;
    };
    //流程ID
    wfm.getWorkflowId = function () {
        var strWorkflowId = '';
        if (data) {
            strWorkflowId = data.WorkflowId;
        }
        return strWorkflowId;
    };
    //流程任务ID
    wfm.getWorktaskId = function () {
        var strWorktaskId = '';
        if (data) {
            strWorktaskId = data.WorktaskId;
        }
        return strWorktaskId;
    };
    //流程实例ID
    wfm.getWorkflowInsId = function () {
        var strWorkflowInsId = '';
        if (data) {
            strWorkflowInsId = data.WorkflowInsId;
        }
        return strWorkflowInsId;
    };
    //流程任务实例ID
    wfm.getWorktaskInsId = function () {
        var strWorktaskInsId = '';
        if (data) {
            strWorktaskInsId = data.WorktaskInsId;
        }
        return strWorktaskInsId;
    };
    //务业表名
    wfm.getTablename = function () {
        var strTablename = '';
        if (data) {
            strTablename = data.Tablename;
        }
        return strTablename;
    };
    //务业表主键
    wfm.getKeyvalue = function () {
        var strKeyvalue = '';
        if (data) {
            strKeyvalue = data.Keyvalue;
        }
        return strKeyvalue;
    };



    //*************************************************************************
    //
    //流程动作
    //
    //**************************************************************************
    //流程起动
    ///Title:流程标题
    /// IsDraft：是否是草稿
    /// Name：不定期控件名称字符串
    /// Value：不定期控件值字符串
    wfm.Start = function (Title, IsDraft, Name, Value) {
        if (data) {
            WF.setTransmitName(_TransmitName);
            WF.Start.init(Title, IsDraft, Name, Value);
        }
    };
    //退回
    wfm.TaskBack = function () {
        if (data) {
            WF.setTransmitName(_TransmitName);
            WF.TaskBack.init(data.OperatorInsId);
        }
    };
    //提交流程事件
    ///CommandName:命令名称。如：“提交”
    wfm.WFRun = function (CommandName) {
        if (data) {
            WF.setTransmitName(_TransmitName);
            WF.WFRun.init(data.OperatorInsId, CommandName);
        }
    };
    //是否退回状态
    wfm.ReturnControl = function () {
        if (data) {
            WF.ReturnControl.init();
        }
    };
    //获取任务实例节点的类型
    wfm.WorkTaskType = function () {
        if (data) {
            WF.WorkTaskType.init(data.WorkflowInsId);
        }
    };
    //更新标题
    ///Title:流程标题
    wfm.UpdateTitle = function (Title) {
        if (data) {
            WF.UpdateTitle.init(data.WorkflowInsId, Title);
        }
    };
    //不定期
    //Values: 不定期控件值字符串
    //Names: 不定期控件名称字符串
    wfm.FreeFlow = function (Values, Names) {
        if (data) {
            WF.FreeFlow.init(data.WorkflowInsId, data.WorktaskId, xValues, Values, Names);
        }
    };

    //审批意见保存
    ///transmitString:转发字符
    ///strUserName:转发人姓名字符串
    ///approvalMessage:审批意见
    wfm.SaveApproval = function (transmitString, strUserName, approvalMessage) {
        var _IsSuccess = '0';
        if (data) {
            _TransmitName = strUserName;
            APP.SaveApproval.init(transmitString, strUserName, approvalMessage);
            _IsSuccess = APP.SaveApproval.getIsSuccess();
        }
        return _IsSuccess;
    };

    return wfm;
})(WFM || {});
